/*
  author:cyhu(viskey.hu@gmail.com) 2015.3.19
  1.Initialize socket with url, connect timetout and reconnection opt.
  
  2.Register the listner for onConnection, onDisconnect, onReconnect
  Event.  
 */
 
(function(window){

	var Connection = function(cfg)
	{
		/* connection url */
		var socket_url                  = 'http://webapi.openspeech.cn:80/ivp';
		
		/* client reconenction */
		var reconnection                = false;
		
		/* reconnection delay */
		var reconnectionDelay           = 999999;
		
		/* create new connection for reconnection while choosing true*/
		var force_new_connection        = true;
		
	    /* socket.io connected state */
	    var KEY_CONNECT                 = 'connect';

	    /* socket.io disconnected state */
	    var KEY_DISCONNECT              = 'disconnect';
	    
		/* session disconnect request */
		var SESSION_DISCONNECT          = 'session_disconnect';
		
		this.regConnListener = function() {
		    
			/**
	         * connect to server, schedule a heartbeat 25s/per 
	         */
	        window.socket.on(KEY_CONNECT, function(data) 
	        {
		        LOGCAT("connected to server ...");
	        });

	        /**
	         * disconnect to server , pop message.
	         */
	        window.socket.on(KEY_DISCONNECT, function()
	        {
		        LOGCAT("disconnect ...");	
	        });

	        window.socket.on(SESSION_DISCONNECT, function()
	        {
		        window.socket.disconnect();
		        LOGCAT("client disconnect ...");
	        });	
		}
	};
	
	window.Connection = Connection;
})(window); 